package cn.imu.appdevexperiment2020.work04;

import android.os.Bundle;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.imu.appdevexperiment2020.R;
import cn.imu.appdevexperiment2020.utils.HttpUtil;
import cn.imu.appdevexperiment2020.work04.adapter.ItemAdapter;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class UserListActivity extends AppCompatActivity {

    private List<UserBean> data = new ArrayList<>();

    void initList() {
        UserBean user1 = new UserBean();
        UserBean userBean = new UserBean();
        UserBean userBean1 = new UserBean();
        userBean1.setUsername("内大考研");
        userBean1.setUserid("45646");
        userBean1.setPhonenumber("17562665214");
        userBean.setPhonenumber("15128752009");
        userBean.setUserid("32209852");
        userBean.setUsername("张喜亮");
        user1.setUsername("胡嘉建");
        user1.setUserid("32209172");
        user1.setPhonenumber("15614177677");
        data.add(user1);
        data.add(userBean);
        data.add(userBean1);

        HttpUtil.get(HttpUtil.ADDR + "/app/user/api/list?sex=0&classesId=110", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                JSONObject parse = JSON.parseObject(response.body().string());
                if (parse.get("code").toString().equals("200")) {
                    //说明解析成功跳转界面
                } else {
                    System.out.println("解析失败");
                }


            }
        });


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_list);
        initList();
        ListView list = findViewById(R.id.list_user);
        list.setAdapter(new ItemAdapter(data, this));

    }
}